package com.hnust.aopdemo.service;

import com.hnust.aopdemo.Entity.Product;
import com.hnust.aopdemo.log.Loggable;
import com.hnust.aopdemo.security.AdminOnly;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ProductService {

    @Autowired
    private AuthService authService;

    @AdminOnly
    public void insert(Product product) {
        //authService.checkAccess();
        System.out.println("insert product");
    }

    @AdminOnly
    public void delete(Long id) {
        //authService.checkAccess();
        System.out.println("delete product by id:" + id);
    }

    public String findById(Long id) {
        //authService.checkAccess();
        System.out.println("findById product by id:" + id);
        return "you are big pig";
    }

    public void findByName(String name) {
        //authService.checkAccess();
        System.out.println("findByName product by name:" + name);
    }

    public List<String> getList(String name) {
        //authService.checkAccess();
        List<String> list = new ArrayList<String>();
        list.add("father");
        list.add("monther");
        System.out.println("findByName product by name:" + name);
        return list;
    }
}
